package  device

import (
	"encoding/json"
	"gitee.com/zhanghuamingmyself/api"
	"gitee.com/zhanghuamingmyself/util"
)

var deviceExplainBaseUrl = "iot/api/v1/v1/device/explain/"

type IotDeviceExplain struct {
	api.BaseDTO
	Port      string      `json:"port"`
	KeyName   string      `json:"keyName"`
	Unit      string      `json:"unit"`
	RawValue  string      `json:"rawValue"`
	ValueDate int32       `json:"valueDate"`
	Value     interface{} `json:"value"`
}

type IotDeviceExplainListReq struct {
	DeviceCore       string `json:"deviceCore"`
	Port             string `json:"port"`
	CanDeviceLinkage *bool `json:"canDeviceLinkage"`
	Hidden           *bool   `json:"hidden"`
}

func ListDeviceExplain(req IotDeviceExplainListReq) ([]IotDeviceExplain, error) {
	var deviceExplainList []IotDeviceExplain
	bytes, err := util.PostJson(deviceExplainBaseUrl+"list", req)
	if err != nil {
		return deviceExplainList, err
	}
	json.Unmarshal(bytes, &deviceExplainList)
	return deviceExplainList, nil
}
